package buffered;

import java.io.*;
import java.util.ArrayList;

public class BufferedReaderTest3 {
    public static void main(String[] args) throws IOException {
        method1();
        ArrayList<Student> list=new ArrayList<>();
        BufferedReader br=new BufferedReader(new FileReader("G:\\Javatest2\\buffered\\stu.txt"));
        String line;
        while((line=br.readLine())!=null){
            Student stu=new Student(line.split("-")[0],Integer.parseInt(line.split("-")[1]));
            list.add(stu);
        }
        for (Student student : list) {
            System.out.println(student.getName()+student.getAge());
        }

    }

    private static void method1() throws IOException {
        Student stu1=new Student("张三",23);
        Student stu2=new Student("李四",24);
        Student stu3=new Student("王五",25);
        BufferedWriter bw=new BufferedWriter(new FileWriter("G:\\Javatest2\\buffered\\stu.txt"));
        bw.write(stu1.getName()+"-"+stu1.getAge());
        bw.newLine();
        bw.write(stu2.getName()+"-"+stu2.getAge());
        bw.newLine();
        bw.write(stu3.getName()+"-"+stu3.getAge());
        bw.close();
    }
}
